<template>
	<view class="print-container">
		<view style="background-color: #f3c45d; padding: 10rpx 30rpx; color: #fff">{{ storeName }}--云打印列表</view>
		<scroll-view class="print-list" scroll-y v-if="printList.length > 0">
			<view class="print-item" v-for="item in printList" :key="item.id">
				<view style="font-size: 32rpx">
					<view style="display: flex; align-items: center">
						<text>{{ item.name }}</text>
						<view class="flag" :style="{ backgroundColor: item.status ? '#5AC725' : '#F9A2A2' }"></view>
					</view>
					<view class="conceal">设备号：{{ item.sn }}</view>
				</view>
				<view style="display: flex">
					<view style="color: #f3c45d; margin-right: 20rpx" @click="onEdit(item)">编辑</view>
					<view style="color: #999" @click="onDel(item.id)">删除</view>
				</view>
			</view>
		</scroll-view>
		<view style="margin-top: 120rpx" v-else>
			<lai-none></lai-none>
		</view>
		<view class="footer-btn">
			<view style="margin-right: 20rpx" class="btn" @click="onEdit(0)">新增云打印机</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-modal :show="show" title="温馨提示" showCancelButton content="确认删除吗？" @cancel="cancel" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
export default {
	data() {
		return {
			storeName: '',
			printList: [],
			show: false,
			id: null
		};
	},
	onShow() {
		this.getPrintList();
		this.storeName = uni.getStorageSync('store').storeName;
	},
	methods: {
		onEdit(row) {
			if (row) {
				uni.navigateTo({
					// url: '/pages/workbench/printSetting/edit?row=' + JSON.stringify(row)
					url: '/pages/workbench/printSetting/edit?id=' + row.id
				});
			} else {
				uni.navigateTo({
					url: '/pages/workbench/printSetting/edit'
				});
			}
		},
		onDel(id) {
			this.show = true;
			this.id = id;
		},
		async confirm() {
			await this.$api.delPrintInfo({ id: this.id });
			this.show = false;
			this.$refs.uToast.show({ type: 'success', message: '解绑成功' });
			this.getPrintList();
		},
		cancel() {
			this.show = false;
		},
		async getPrintList() {
			const res = await this.$api.getPrintList();
			this.printList = res.data || [];
		}
	}
};
</script>

<style scoped lang="scss">
.print-container {
	background-color: #fff;
	min-height: 100vh;
	.print-list {
		height: calc(100vh - 180rpx);
		padding: 30rpx 20rpx 0;

		.print-item {
			display: flex;
			align-items: center;
			border: 1px solid #f3f4f6;
			height: 100rpx;
			padding: 0 30rpx;
			border-radius: 10rpx;
			justify-content: space-between;
			margin-bottom: 25rpx;
		}
	}
	.footer-btn {
		position: fixed;
		bottom: 0%;
		left: 0%;
		width: 100%;
		height: 120rpx;
		display: flex;
		border-top: 1px solid #f3f4f6;
		align-items: center;
		justify-content: center;
		padding: 20rpx 50rpx;
		.btn {
			width: 45%;
			height: 100rpx;
			border-radius: 50rpx;
			background-color: #f3c45d;
			color: #fff;
			line-height: 100rpx;
			font-size: 30rpx;
			text-align: center;
		}
	}
}
.conceal {
	font-size: 24rpx;
	color: #999;
	margin-top: 8rpx;
}
.flag {
	width: 10rpx;
	height: 10rpx;
	// background-color: green;
	border-radius: 5rpx;
	margin-left: 15rpx;
}
</style>
